from rest_framework import serializers

from doctor.models import MajorModel, DeptModel, RankModel, DoctorModel, ConsultationModel
from user.userser import UserSerializer


class MajorSerializer(serializers.ModelSerializer):
    class Meta:
        model = MajorModel
        fields = '__all__'


class DeptSerializer(serializers.ModelSerializer):
    class Meta:
        model = DeptModel
        fields = '__all__'


class RankSerializer(serializers.ModelSerializer):
    class Meta:
        model = RankModel
        fields = '__all__'


class DoctorSerializer(serializers.ModelSerializer):
    d_img = serializers.ImageField(required=False)
    major_name = serializers.SerializerMethodField(read_only=True)
    dept_name = serializers.SerializerMethodField(read_only=True)
    rank_name = serializers.SerializerMethodField(read_only=True)

    def get_major_name(self, obj):
        return obj.major.m_name

    def get_dept_name(self, obj):
        return obj.dept.de_name

    def get_rank_name(self, obj):
        return obj.rank.r_name

    class Meta:
        model = DoctorModel
        fields = '__all__'


class ConsultationSerializer(serializers.ModelSerializer):
    doctor = DoctorSerializer(read_only=True)
    user = UserSerializer(read_only=True)

    class Meta:
        model = ConsultationModel
        fields = '__all__'


class ConsultationSer(serializers.ModelSerializer):
    class Meta:
        model = ConsultationModel
        fields = '__all__'
